/*
 *  Copyright (C) 2011 glauco
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.balisunrise.swing.components;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.logging.Level;
import org.balisunrise.application.Application;
import org.balisunrise.builder.CommonFactory;
import org.balisunrise.builder.FactoryException;
import org.balisunrise.common.Event;
import org.balisunrise.common.FieldAction;
import org.balisunrise.common.FieldLayout;

/**
 *
 * @author glauco
 */
public class FieldActionMouseListener implements MouseListener{

    FieldAction fa;

    public FieldActionMouseListener(FieldAction fa) {
        this.fa = fa;
    }
    
    @Override
    public void mouseClicked(MouseEvent e) {
        Event event = null;
        try{
            FieldLayout fl = null;
            if (fa.getOwner() instanceof FieldLayout)
                fl = (FieldLayout) fa.getOwner();
            event = CommonFactory.getFactory()
                    .createFieldActionEvent(fa, fl);
        }catch(FactoryException ex){
            Application.get().getLogger().log(Level.SEVERE,
                    "FieldActionMouseListener não pode criar FieldActionEvent",
                    ex);

        }

        fa.perform(event);
    }

    @Override
    public void mousePressed(MouseEvent e) { }

    @Override
    public void mouseReleased(MouseEvent e) { }

    @Override
    public void mouseEntered(MouseEvent e) { }

    @Override
    public void mouseExited(MouseEvent e) { }

    }
